// pages/read/read.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    msg1: "这是一条测试数据",
    msg2: "这是一条测试数据",
    time1: "一",
    time2: "两",
    userName1: "张三",
    userName2 : "李丽",
    msgList : [],
    msgList_bk : [
      {
        userName : "张三",
        msg : "这是第一条数据",
      },
      {
        userName: "李四",
        msg: "这是第二条数据",
      },
      {
        userName: "王五",
        msg: "这是第三条数据",
      },
      {
        userName: "赵六",
        msg: "这是第四条数据",

      }, 
      {
        userName: "李四",
        msg: "这是第五条数据",

      },


    ],
  },

  /**
   * 组件的方法列表
   */
  methods: {


  },
  
  attached: function(){
    let that = this;
    let messageList;
    wx.request({
      url: 'http://120.79.197.164:9285/barter/post/getPostList',
      method: 'POST',
      data: {
        pageNum : 1,
        pageSize : 100,
        title : "",
        userId : wx.getStorageSync('uuid'),
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        messageList = res.data.data;
        var msgArr;
        for (var i = 0; i < messageList.length; i++) {
          var j = i;
          // msgArr = messageList;
          // msgArr.push(messageList[j]);
          wx.request({
            url: 'http://120.79.197.164:9285/barter/user/getUserByUserId/' + messageList[j].userId,
            method: 'GET',
            data: {
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success(res) {
              // console.log(res.data.data);
              // console.log(messageList[j]);

              messageList[j].userName = res.data.data.userName;
              messageList[j].sex = res.data.data.sex;
              msgArr = messageList;
              // console.log(msgArr[j]);
              // console.log(j);
              // msgArr.push(messageList[j]);
              
              that.setData({
                msgList: msgArr,
              });
            }

          });
        }
        // msgArr = messageList;
        // console.log(that.data.msgList);
        // console.log(msgArr[0].sex);
        // that.setData({
        //   msgList: msgArr,
        // });

        // console.log(this.data.msgList);

      }

    });

  }

});
